﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.SourceLogic
{
    public class SourceCommand : SyncEsgCommand<Source>
    {
        private readonly IMongoCollection<Source> sourceMongoCollection;

        public SourceCommand(IMongoCollection<Source> sourceMongoCollection, ILogger logger) : base(logger)
        {
            this.sourceMongoCollection = sourceMongoCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds = null, Guid? additionalDiscriminator = null)
        {
            return await sourceMongoCollection.DeleteManyAsync(Builders<Source>.Filter.Empty).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<Source> entities)
        {
            await sourceMongoCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
